﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace APRIL
{
    public partial class SetSerialPortForm : Form
    {
        public System.IO.Ports.SerialPort serialPort = new System.IO.Ports.SerialPort();
        public SetSerialPortForm()
        {
            InitializeComponent();
        }
        public SetSerialPortForm(System.IO.Ports.SerialPort sp)
        {
            InitializeComponent();
            serialPort = sp;
        }
        private void SetSerialPortForm_Load(object sender, EventArgs e)
        {
            string[] PortName = System.IO.Ports.SerialPort.GetPortNames();  // 获取串口名字
            cboCommPort.Items.AddRange(PortName);
            if (cboCommPort.FindString(serialPort.PortName) != -1)
            {
                cboCommPort.SelectedIndex = cboCommPort.FindString(serialPort.PortName);//0;
            }
            else
                cboCommPort.SelectedIndex = 0;
            if (cboBandRate.FindString(serialPort.BaudRate.ToString()) != -1)
                cboBandRate.SelectedIndex = cboBandRate.FindString(serialPort.BaudRate.ToString());
            else
                cboBandRate.SelectedIndex = 3;
        
            //serialPort = new System.IO.Ports.SerialPort();
            serialPort.Parity = System.IO.Ports.Parity.Even;
        }

        private void cboCommPort_SelectedIndexChanged(object sender, EventArgs e)
        {
            serialPort.PortName = cboCommPort.SelectedItem.ToString();
        }

        private void cboBandRate_SelectedIndexChanged(object sender, EventArgs e)
        {
            serialPort.BaudRate = Int32.Parse(cboBandRate.SelectedItem.ToString());
        }
    }
}
